<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/8
 * Time: 10:45
 */
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;

class Suiniya extends controller{

    public function suiniya(){
        $search = input('get.');

        $where = [];
        if( isset($search['sid']) && $search['sid']){
            $where['f_suiya.id'] = $search['sid'];
        }

        if( isset($search['phone']) && $search['phone']){
            $where['f_user.phone'] = $search['phone'];
        }
        if( isset($search['uname']) && $search['uname']){
            $where['f_user.nickname'] = $search['uname'];
        }

        if(isset($search['datemin']) && $search['datemax']!="" && isset($search['datemin']) && $search['datemax']!=""){
            $min = $search['datemin'];
            $max = $search['datemax'];

            $where['f_suiya.createtime'] = ['between',[$min,$max]];
        }
       // print_r($where);die;
            $res=db('suiya')
                ->join('f_user','f_suiya.uid=f_user.uid')
                ->field('f_suiya.*,f_user.uname,f_user.nickname,head_portrait,f_user.phone,f_user.avatars_img')
              	->order('createtime desc')
                ->where($where);
            $rs=db('suiya')
                ->where($where)
              ->join('f_user','f_suiya.uid=f_user.uid')
              ->count();
        $res=$res->paginate(10,false,['query'=>request()->param()]);
        $page=$res->render();
        return view('suiniya',['res'=>$res,'page'=>$page,'rs'=>$rs,'query'=>$search]);


    }
    public function updatesny(){
        $id=input('zid');
        $data=['flg'=>1];
        $rs=db('suiya')
            ->where('id',$id)
            ->update($data);
        if($rs){
            return 1;
        }else{
            return 0;
        }
    }
//    随你压设置
    public function suiniyashezhi(){
        if(request()->isAjax()){
            $date=["workdate"=>input('workdate'),"way"=>input('way'),"tel"=>input('tel')];
            $rs=db('suiyas')->where('id',1)->update($date);
            if($rs){
                return array('code'=>1,'msg'=>'成功'
                            );
            }
            else{
               return array('code'=>0,'msg'=>'失败');
            }
        }else{
           $res=db('suiyas')->find();
            return view('suiniyashezhi',['res'=>$res]);
        }

    }
}
